func minSubArrayLen(target int, nums []int) int {
    sum := 0
    min := len(nums)+1
    l := 0
    for r:=0; r<len(nums); r++ {
        sum += nums[r]
        for sum >= target {
            min = minNum(min, r-l+1)
            sum -= nums[l]
            l++
        }
    }
    if min == len(nums)+1{
        return 0
    }
    return min
}

func minNum(a, b int) int {
    if a < b {
        return a
    }
    return b
}